package self.mld.codelab2.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import self.mld.codelab2.entity.User;
import self.mld.codelab2.service.UserService;

import java.util.List;

@Controller
public class UserController {
    @Autowired
    private UserService userService;

    @ResponseBody
    @RequestMapping(value = "/users", method = RequestMethod.GET)
    public List<User> users() {
        return userService.getAll();
    }


    @ResponseBody
    @RequestMapping(value = "/users/add", method = RequestMethod.POST)
    public User add(User user) {
        userService.save(user);
        return userService.getOne(user.getId());
    }


    @RequestMapping(value = "/users/register", method = RequestMethod.GET)
    public String register() {
        return "register";
    }
}
